﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_OpenApiConfig : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "ApiUrl",
                table: "MainStConfig");

            migrationBuilder.RenameColumn(
                name: "SchemaJson",
                table: "MainStColumnConfig",
                newName: "Type");

            migrationBuilder.AddColumn<Guid>(
                name: "OpenApiConfigId",
                table: "SfConfig",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "OpenApiConfigId",
                table: "MainStConfig",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Field",
                table: "MainStColumnConfig",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "HeaderName",
                table: "MainStColumnConfig",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "MainOpenApiConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    OpenApiConfigCodg = table.Column<string>(type: "text", nullable: false),
                    OpenApiConfigName = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainOpenApiConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainOpenApiConfig_MainProjectConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainProjectConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainOpenApiConfig_ProjectConfigId",
                table: "MainOpenApiConfig",
                column: "ProjectConfigId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainOpenApiConfig");

            migrationBuilder.DropColumn(
                name: "OpenApiConfigId",
                table: "SfConfig");

            migrationBuilder.DropColumn(
                name: "OpenApiConfigId",
                table: "MainStConfig");

            migrationBuilder.DropColumn(
                name: "Field",
                table: "MainStColumnConfig");

            migrationBuilder.DropColumn(
                name: "HeaderName",
                table: "MainStColumnConfig");

            migrationBuilder.RenameColumn(
                name: "Type",
                table: "MainStColumnConfig",
                newName: "SchemaJson");

            migrationBuilder.AddColumn<string>(
                name: "ApiUrl",
                table: "MainStConfig",
                type: "text",
                nullable: false,
                defaultValue: "");
        }
    }
}
